{% extends "GitonomyWebsiteBundle::layout_project.html.twig" %}

{% set global_navigation = 'projects' %}
{% set local_navigation = 'branches' %}
{% trans_default_domain 'project_branches' %}

{% block title 'page.title'|trans({'%project%': project.name}) %}

{% block project_content %}
    <div id="content">
        <table class="table">
            <thead>
                <tr>
                    <th>{{ 'table.column.branch'|trans }}</th>
                    <th>{{ 'table.column.last_commit'|trans }}</th>
                    <th>{{ 'table.column.author'|trans }}</th>
                    <th>{{ 'table.column.date'|trans }}</th>
                    <th>{{ 'table.column.diff'|trans }}</th>
                    <th>{{ 'table.column.actions'|trans }}</th>
                </tr>
            </thead>
            <tbody>
                {% for row in branches_activity(project) %}
                    {% set branch = row.branch %}
                    <tr>
                        <td>
                            {{ branch.name }}
                        </td>
                        <td><a href="{{ path('project_commit', {slug: project.slug, hash: branch.commit.hash}) }}">{{ branch.commit.fixedShortHash }}</a> {{ branch.commit.shortMessage }}</td>
                        <td class="author">
                            <img class="avatar" src="{{ gravatar(branch.commit.authorEmail, 16) }}" alt="{{ branch.commit.authorName }}" title="{{ branch.commit.authorName }}" />
                            {{ branch.commit.authorName }}
                        </td>
                        <td>{{ branch.commit.authorDate.format('Y-m-d H:i:s') }}</td>
                        <td>
                            {% if row.behind or row.above %}
                                {% if row.behind %}<span class="behind">-{{ row.behind }}</span>{% endif %}
                                {% if row.above %}<span class="above">+{{ row.above }}</span>{% endif %}
                            {% endif %}
                        </td>
                        <td>
                            <div class="btn-group pull-right">
                                {% if reference != branch.name %}
                                    <a rel="tooltip" class="btn btn-small" href="{{ path('project_branches', {slug: project.slug, reference: branch.name}) }}" data-original-title="{{ 'button.compare'|trans }}"><i class="icon-star"></i>
                                    </a>
                                {% endif %}

                                {% if row.behind or row.above %}
                                    <a rel="tooltip" class="btn btn-small" href="{{ path('project_compare', {slug: project.slug, revision: reference~'...'~branch.name}) }}" data-original-title="{{ 'button.diff'|trans }}"><i class="icon-eye-close"></i>
                                    </a>
                                {% endif %}

                                {% if is_granted('GIT_DELETE', [project, branch.fullname]) %}
                                    <a data-method="POST" data-confirm="{{ 'button.delete_confirm'|trans }}" rel="tooltip" class="btn btn-small btn-danger" href="{{ path('project_branchDelete', {slug: project.slug, branch: branch.name}) }}" data-original-title="{{ 'button.delete'|trans({'%branch%': branch.name}) }}"><i class="icon-fire icon-white"></i>
                                    </a>
                                {% endif %}
                            </div>
                        </td>
                    </tr>
                {% else %}
                    <tr>
                        <td colspan="4">No Branches found</td>
                    </tr>
                {% endfor %}
            </tbody>
        </table>
    </div>
{% endblock %}
